﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Map;
using System.Windows.Forms;
using DotSpatial .Main ;
using DotSpatial .Drawing ;


using DotSpatial.Data;

using DotSpatial.Geometries;



namespace HuanGis
{
   public  class FLayerManager
   {

       //#region 事件相关的代码
       //public event LayerAddHandler  LayerAdded;

       //public event LayerShapeHandler AskShapeAdded;
       //public event LayerShapeHandler AskShapeRemoved;
       //public event LayerShapeHandler AskShapeModified;



       //#endregion 


       //Dictionary<string, FLayer> m_Layers=new Dictionary<string ,FLayer>() ;


     


    
       /// <summary>
       /// 公共的构造函数
       /// </summary>
       public FLayerManager(Map m)
       {
           m_Map = m;

        

           //订阅对应的事件处理模型
           this.PrepareEvent();



          


           //自定义功能区

           //辅助绘制管理器
           m_MfSystem = new MFManager( m_Map,this);

           //文件位置管理器


           m_PathManager = new PathManager();


           m_Layers = new LayerSystem(this);
         
          

         

       }


       protected Map m_Map;

       /// <summary>
       /// 返回当前的图形接口
       /// </summary>
       public Map CurrentMap
       {
           get { return m_Map; }
       }


       protected PathManager m_PathManager;

       /// <summary>
       /// 路径管理器
       /// </summary>
       public PathManager PathManager
       {
           get { return m_PathManager; }
          
       }


     


        MFManager m_MfSystem;

       /// <summary>
       /// 主编辑模型管理系统
       /// </summary>
        public MFManager MfSystem
        {
            get { return m_MfSystem; }
           
        }



       /// <summary>
       /// 图层主管理系统
       /// </summary>
        LayerSystem m_Layers;

        /// <summary>
        /// 图层主管理系统
        /// </summary>
        public LayerSystem LayerSystem
        {
            get { return m_Layers; }
           
        }




        protected  bool bNullProj = true;

        public bool BNullProj
        {
            get { return bNullProj; }
           
        }



       #region 事件的处理模块，与订阅


       /// <summary>
       /// 建立对应的事件处理程序
       /// </summary>
       protected  void PrepareEvent()
       {

           //鼠标
           m_Map.MouseDown += new MouseEventHandler(m_Map_MouseDown);
           m_Map.MouseUp += new MouseEventHandler(m_Map_MouseUp);
           m_Map.MouseMove += new MouseEventHandler(m_Map_MouseMove);
           m_Map.MouseDoubleClick += new MouseEventHandler(m_Map_MouseDoubleClick);

           

           //键盘
           m_Map.KeyDown += new KeyEventHandler(m_Map_KeyDown);

          
           //其它重要功能
           m_Map.SelectionChanged += new EventHandler(m_Map_SelectionChanged);

       }

       void m_Map_SelectionChanged(object sender, EventArgs e)
       {
            
       }

       //键盘处理
       void m_Map_KeyDown(object sender, KeyEventArgs e)
       {
           

           e.Handled = true;

       }



       //鼠标处理

       void m_Map_MouseDoubleClick(object sender, MouseEventArgs e)
       {
          
       }

       void m_Map_MouseMove(object sender, MouseEventArgs e)
       {
           
       }

       void m_Map_MouseUp(object sender, MouseEventArgs e)
       {
         
       }

       void m_Map_MouseDown(object sender, MouseEventArgs e)
       {
          
       }



       #endregion

       #region 文件管理

       public bool SaveProj()
       {
           return this.m_Layers.SaveProj();

           
       }

       public bool OpenProj(string pfName)
       {

          bool b= this.m_Layers.OpenProj(pfName );

          if (b)
          {
              m_PathManager.ProjPath = pfName;

              return true;

          }
          else
          {
              return false;
          }

          



          
 
       }

       public void NewProj(string pfName)
       {

           this.m_Layers.NewProj(pfName );
           m_PathManager.ProjPath = pfName;


 
       }



       public bool SaveAsProj(string pfName)
       {
           this.m_Layers.SaveAsProj(pfName );
           return true;
       }






       #endregion





      
    

       public void AddLayer(FLayer  layer)
       {
           this.m_Layers.AddLayer(layer );

         
 
       }


       public void RemoveLayer(string id)
       {
           this.m_Layers.RemoveLayer(id);
 
       }


       public void RemoveAllLayer()
       {
           this.m_Layers.RemoveAllLayer();
 
       }



       public FLayer  GetLayer(string lname)
       {

           return this.m_Layers.GetLayer(lname);
 
       }









    }
}
